/*
 * listener.h
 */

#ifndef LISTENER_H_
#define LISTENER_H_

#include "event.h"

/*
 * The listener node.
 * This structure stores an event handler to be executed when the action this
 * listener is listening for is executed and a pointer to the next listener node
 * in the list.
 */
struct listener_node {
    void (*on_event)(event*);
    struct listener_node *next;
};

/*
 * The listener. This is intended to be the structure used by other modules,
 * which is why it is typedef'd.
 * It is simply a pointer to the first node in the linked list of
 * listener_nodes.
 */
typedef struct {
    struct listener_node *head;
} listener;

/*
 * Registers the given event handler for the given listener.
 * A new listener_node is created for the function and added to the list.
 */
void listener_register( event_t type, void (*on_event)(event*) );

/*
 * Frees the given listener structure and all listener_nodes in the given
 * listener's list.
 */
void listener_free(listener *list);

/*
 * Calls all event handlers in the given listener.
 */
void listener_inform( event *e );

/*
 * List of registered listener types.
 */
int listener_init();

#endif
